package info.manxi;

import akka.actor.AbstractActor;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;

/**
 * Hello world!
 */
public final class App {
    private App() {
    }

    /**
     * Says hello to the world.
     *
     * @param args The arguments of the program.
     */
    public static void main(String[] args) {
        ActorSystem system = ActorSystem.create("www-manxi-info");
        System.out.println(system);
        system.actorOf(Props.create(Start.class)).tell("", ActorRef.noSender());
    }

    static class Start extends AbstractActor {

        @Override
        public Receive createReceive() {
            return receiveBuilder()
                    .matchAny(m -> {
                        final ActorRef buncher = getContext().system().actorOf(Props.create(Buncher.class));
                        final ActorRef probe = getContext().system().actorOf(Props.create(Target.class));

                        buncher.tell(new 设置目标事件(probe), getSelf());
                        buncher.tell(new 入队事件(42), probe);
                        buncher.tell(new 入队事件(43), probe);
                        buncher.tell(new 入队事件(44), probe);
                        buncher.tell(清空事件.Flush, probe);
                        buncher.tell(new 入队事件(45), probe);
                    })
                    .build();
        }
    }

    static class Target extends AbstractActor {
        @Override
        public Receive createReceive() {
            return receiveBuilder()
                    .matchAny(m -> {
                        System.out.println("yes it is : " + m /*+ " FROM " + getSender()*/);
                    })
                    .build();
        }
    }
}
